package com.ruicar.afs.cloud.basic.proceeds.business.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.basic.api.corporate.dto.CorporateTransferApprovedDTO;
import com.ruicar.afs.cloud.basic.api.corporate.dto.DealCorporateResultDto;
import com.ruicar.afs.cloud.basic.common.service.BasicMainInfoService;
import com.ruicar.afs.cloud.basic.common.service.BasicReceiptRecordService;
import com.ruicar.afs.cloud.basic.proceeds.mq.sender.FinanceSender;
import com.ruicar.afs.cloud.batch.service.AfsBatchInfoService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-20 15:40
 */
@Slf4j
@RestController
@RequestMapping("/corporateTransfer")
@AllArgsConstructor
@ConditionalOnProperty(prefix = "com.ruicar.afs.cloud.mq.rabbit",name="enable")
public class CorporateTransferController {

    private final BasicReceiptRecordService basicReceiptRecordService;
    private final BasicMainInfoService basicMainInfoService;
    private final AfsBatchInfoService afsBatchInfoService;


    public Date getBatchDate(){
        return DateUtil.parse(afsBatchInfoService.getSystemBatchInfo("icos").getBatchDate(), DatePattern.PURE_DATE_PATTERN);
    }

    private final FinanceSender financeSender;
    private final BasicMainInfoService mainInfoService;


    @ApiOperation(value = "对公结算审核通过")
    @PostMapping("/approved")
    public IResponse<DealCorporateResultDto> corporateTransferApproved(@RequestBody CorporateTransferApprovedDTO corporateTransferApprovedDTO){
        return basicReceiptRecordService.corporateTransferApproved(corporateTransferApprovedDTO,getBatchDate());
    }
}
